<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>新增旅客信息</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link href="/weixin/css/mui.min.css" rel="stylesheet" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-back mui-pull-left"></a>
		    <h1 id="headerTitle" class="mui-title">新增旅客信息</h1>
		    <button class="mui-btn mui-btn-blue mui-btn-link mui-pull-right" id="addPassengerBtn">保存</button>
		</header>
		<div class="mui-content">
			<form class="mui-input-group" id="addPassengerForm">
				<div class="mui-input-row">
					<label>姓名</label>
					<input type="text" id="pasName" name="pasName" class="mui-input-clear" placeholder="姓名" maxlength="20">
				</div>
				<div class="mui-input-row">
					<label>手机号</label>
					<input type="tel" id="pasTel" name="pasTel" class="mui-input-clear" placeholder="手机号"  maxlength="15">
				</div>
				<div class="mui-input-row">
					<label>身份证号</label>
					<input type="text" id="pasCard" name="pasCard" class="mui-input-clear" placeholder="身份证号" maxlength="18">
				</div>
			</form>
		</div>
		<script src="/weixin/js/mui.min.js"></script>
		<script src="/weixin/js/jquery.min.js"></script>
		<script src="/weixin/js/comment.js"></script>
		<script type="text/javascript">
			mui.init();
			
			mui.ready(function(){
		        //获得url carInfoId参数
		        var passengerId = getUrlParam('passengerId');
		        
		        //修改操作
		        if(passengerId!=''){
		        	jQuery("#headerTitle").text("修改旅客信息");
		        	//获得旅客信息
			        setTimeout(function(){
			        	jQuery.ajax({
			        		type:'get',
			        		url:ajaxUrlPath+'/wx/info/detail',
			        		data:{
			        			id:passengerId
			        		},
			        		async:true,
			        		success:function(data){
			        			if(data!=null){
			        				jQuery('#pasName').val(data.name);
			        				jQuery('#pasTel').val(data.mobile);
			        				jQuery('#pasCard').val(data.idNumber);
			        				jQuery("#addPassengerBtn").attr('data-id',data.id);
			        			}
			        		}
			        	});
			        },200);
		        }
		        
		        //保存旅客信息
		        jQuery('#addPassengerBtn').bind('click',function(){
		        	var name=jQuery('#pasName').val();
		        	 // 判断中文姓名
					 if(jQuery.trim(name).length == 0) {
					  	mui.alert('请输入姓名', '美丽乡村');
		        		return false;
					 } else {
					  if(isChinaName(jQuery.trim(name)) == false) {
					   	mui.alert('请输入中文姓名', '美丽乡村');
		        		return false;
					  }
					 }
					
    				var tel=jQuery('#pasTel').val();
    				 // 判断手机号码
					 if (jQuery.trim(tel).length == 0) { 
						 mui.alert('请输入手机号', '美丽乡村');
		        		 return false;
					} else {
						if(isPhoneNo(jQuery.trim(tel)) == false) {
						     mui.alert('请输入正确的手机号', '美丽乡村');
		        			 return false;
						}
					 }
					
    				var card=jQuery('#pasCard').val();
    				if(jQuery.trim(card).length == 0) { 
					  	 mui.alert('请输入身份证号', '美丽乡村');
		        		 return false;
					 } else {
					   if(isCardNo($.trim(card)) == false) {
					  		 mui.alert('请输入正确的身份证号', '美丽乡村');
		        			 return false;
					  	}
					 }
    				
    				var id=jQuery("#addPassengerBtn").attr('data-id');
    				jQuery.ajax({
		        		type:'get',
		        		url:ajaxUrlPath+'/wx/info/save',
		        		data:{
		        			touristId:id,
		        			name:name,
		        			mobile:tel,
		        			idNumber:card
		        		},
		        		async:true,
		        		success:function(data){
		        			if(data=='success'){
		        				mui.alert('保存成功', '美丽乡村', function() {
									window.location='passenger-info.html';
								});
		        			}
		        		}
		      		});
		        });
			});
		</script>
	</body>

</html>